package com.ourhours.redismq.demo.message.handler;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.ourhours.redismq.AbstarctMessageHandler;

/**
 * DemoMessage消息的处理器
 * 
 * @category @author xiangyong.ding@weimob.com
 * @since 2017年2月3日 下午9:21:41
 */
@Service
public class TestHandler extends AbstarctMessageHandler
{
	private static Logger log = LoggerFactory.getLogger(TestHandler.class);

	public TestHandler()
	{
		// 说明该handler监控的消息类型
		super("test", 10);
	}
	
	@PostConstruct
	public void testLog() {
		log.debug("TestListener-testLog-debug");
		log.info("TestListener-testLog-info");
		log.error("TestListener-testLog-error");
	}

	/**
	 * 监听到消息后处理方法
	 */
	@Override
	public void handle(String message)
	{

		System.out.println("正在处理消息：" + message);
	}

	@Override
	public void handleFailed(String obj)
	{
		StringBuilder sb = new StringBuilder();
		sb.append("msg:[").append(obj).append("], 超过失败次数，停止重试。");
		log.warn(sb.toString());
	}

}
